﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class registe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    /// <summary>
    ///  创建账号
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>

    protected void insertButton_Click(object sender, EventArgs e)
    {
        BLL.Business.UserBLL userBLL = new BLL.Business.UserBLL();
        Model.User user = new Model.User();
        try
        {
            //----------------------
            String userName = this.TextBox1.Text.ToString();
            String password = this.TextBox2.Text.ToString();
            String email = this.TextBox4.Text.ToString();
            String problem = "";
            String answer = "";
            if (this.secproblem.Value != null)
            {
                problem = this.secproblem.Value;
                answer = this.TextBox5.Text.ToString();
            }
            //----------------------
            if (!userBLL.IsExist(userName))// 不存在
            {
                user.User_Addressstr = "地球 中国";
                user.User_Answerstr = answer;
                user.User_Mailstr = email;
                user.User_Namestr = userName;
                user.User_Passwordstr = password;
                user.User_Questionstr = problem;
                user.User_Telephonestr = "158888888";

                if (userBLL.Insert(user))     // 添加成功，跳转至用户中心（或是首页）
                {
                    Session["UserName"] = userName;  
                    Response.Redirect("userCenter.aspx");
                }
                else
                {
                    Response.Write("<script>alert('对不起，注册出现问题，请查证！')</script>"); 
                }
            }
            else                           // 已经存在
            {
                Response.Write("<script>alert('该用户已存在！')</script>"); 
            }
        }
        catch(Exception ex )
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
        }
    }
}
